package com.ninong.ker.admin.rest;

import com.ninong.ker.admin.service.FwJobService;
import com.ninong.ker.common.tools.enums.BusinessEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ninong.ker.admin.domain.FwJob;
import com.ninong.ker.admin.service.dto.FwJobDTO;


import com.ninong.ker.common.annotation.perm.CmdAdmin;
import com.ninong.ker.common.response.CmdResponse;



/**
 * 
 *
 * @author 鸠摩智
 * @email 
 * @date 2021-06-04 10:45:47
 */
@RestController
@RequestMapping("gen/v1/fwjob")
public class FwJobResouces {

    @Autowired
    private FwJobService fwJobService;

    /**
     * 列表
     */
    @CmdAdmin({"admin","job:list"})
    @PostMapping
    public ResponseEntity<CmdResponse> list(@RequestBody FwJobDTO dto){
		CmdResponse response = new CmdResponse();
		response.setData(fwJobService.listPage(dto));
		return ResponseEntity.ok(response);
    }


	@CmdAdmin({"admin","job:delete"})
	@DeleteMapping
	public ResponseEntity<CmdResponse> delete(@RequestBody String[] ids)  {
		fwJobService.delete(ids);
		CmdResponse response = new CmdResponse();
		response.setMessage(BusinessEnum.DELETE_SUCCESS.getMsg());
		return ResponseEntity.ok(response);
	}
	
	@CmdAdmin({"admin","job:add","job:update"})
	@PutMapping
	public ResponseEntity<CmdResponse> add(@RequestBody FwJob entity) throws Exception  {
		fwJobService.insert(entity);
		return ResponseEntity.ok(new CmdResponse());
	}
	
	@CmdAdmin({"admin","job:detail"})
	@GetMapping(value = "/{id}")
	public ResponseEntity<CmdResponse> get(@PathVariable String id)  {
		CmdResponse response = new CmdResponse();
		response.setData(fwJobService.get(id));
		return ResponseEntity.ok(response);
	}

}
